<template>
  <div class="app-container">


    <el-row :gutter="10" class="mb8">


      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['order:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <template>


  <el-tabs :tab-position="tabPosition" style="height: 800px;">
    <el-tab-pane label="洗车订单">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单号" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="state">

        <el-select v-model="queryParams.state" placeholder="请选择">
      <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
     </el-option>
      </el-select>


      </el-form-item>
      <el-form-item label="下单时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
      <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单编号" align="center" prop="id" />
      <el-table-column label="服务编号" align="center" prop="number" />
      <el-table-column label="服务名称" align="center" prop="serviceName" />
      <el-table-column label="买家" align="center" :formatter="formatUserInfo"  prop="userName">
      <template slot-scope="{ row }">
    <span v-html="row.userName"></span>
  </template>
      </el-table-column>
      <el-table-column label="商家" align="center" prop="shopName" />

      <el-table-column label="优惠" align="center" :formatter="formatUserInfo" prop="abc" >
        <template slot-scope="{ row }">
    <span v-html="row.abc"></span>
  </template>
      </el-table-column>

      <el-table-column label="状态" align="center" prop="state">

</el-table-column>
      <el-table-column label="预约时间" align="center" prop="subscribeTime" width="180"></el-table-column>
      <el-table-column label="下单时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['order:order:edit']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table></el-tab-pane>
    <el-tab-pane label="维修订单">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单号" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="state">

        <el-select v-model="queryParams.state" placeholder="请选择">
      <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
     </el-option>
      </el-select>


      </el-form-item>
      <el-form-item label="下单时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery2">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
      <el-table v-loading="loading" :data="orderList2" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单编号" align="center" prop="id" />
      <el-table-column label="服务编号" align="center" prop="number" />
      <el-table-column label="服务名称" align="center" prop="serviceName" />
      <el-table-column label="买家" align="center" :formatter="formatUserInfo"  prop="userName">
      <template slot-scope="{ row }">
    <span v-html="row.userName"></span>
  </template>
      </el-table-column>
      <el-table-column label="商家" align="center" prop="shopName" />

      <el-table-column label="优惠" align="center" :formatter="formatUserInfo" prop="abc" >
        <template slot-scope="{ row }">
    <span v-html="row.abc"></span>
  </template>
      </el-table-column>

      <el-table-column label="状态" align="center" prop="state">

</el-table-column>
      <el-table-column label="预约时间" align="center" prop="subscribeTime" width="180"></el-table-column>
      <el-table-column label="下单时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['order:order:edit']"
          >详情</el-button>

        </template>
      </el-table-column>
    </el-table></el-tab-pane>
    <el-tab-pane label="保养订单">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单号" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="state">

        <el-select v-model="queryParams.state" placeholder="请选择">
      <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
     </el-option>
      </el-select>


      </el-form-item>
      <el-form-item label="下单时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="aa">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
      <el-table v-loading="loading" :data="orderList3" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单编号" align="center" prop="id" />
      <el-table-column label="服务编号" align="center" prop="number" />
      <el-table-column label="服务名称" align="center" prop="serviceName" />
      <el-table-column label="买家" align="center" :formatter="formatUserInfo"  prop="userName">
      <template slot-scope="{ row }">
    <span v-html="row.userName"></span>
  </template>
      </el-table-column>
      <el-table-column label="商家" align="center" prop="shopName" />

      <el-table-column label="优惠" align="center" :formatter="formatUserInfo" prop="abc" >
        <template slot-scope="{ row }">
    <span v-html="row.abc"></span>
  </template>
      </el-table-column>

      <el-table-column label="状态" align="center" prop="state">

</el-table-column>
      <el-table-column label="预约时间" align="center" prop="subscribeTime" width="180"></el-table-column>
      <el-table-column label="下单时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['order:order:edit']"
          >详情</el-button>

        </template>
      </el-table-column>
    </el-table></el-tab-pane>
    <el-tab-pane label="评价管理">
      <el-form :model="queryParams1" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="订单号" prop="orderIdw">
        <el-input
          v-model="queryParams1.orderIdw"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星级" prop="score">

        <el-select v-model="queryParams1.score" placeholder="请选择">
      <el-option
      v-for="item in options1"
      :key="item.value"
      :label="item.label"
      :value="item.value">
     </el-option>
      </el-select>


      </el-form-item>
      <!-- <el-form-item label="下单时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery4">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
      <el-table v-loading="loading" :data="orderList4" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单编号" align="center" prop="orderIdw" />
      <el-table-column label="服务内容" align="center" prop="service" >

      </el-table-column>
      <el-table-column label="评价者" align="center" prop="userName" />
      <el-table-column label="星级" align="center"   prop="score">

      </el-table-column>
      <el-table-column label="评价图片" align="center" prop="images"  >
        <template slot-scope="{ row }">
          <img :src="row.images" />
      </template>
      </el-table-column>
      <el-table-column label="评价内容" align="center" prop="comments" />
      <el-table-column label="评价时间" align="center"  prop="commentTime" >
      </el-table-column>
      </el-table>
    </el-tab-pane>
  </el-tabs>

</template>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog  :visible.sync="open" width="1200px" append-to-body>
      <el-descriptions class="margin-top" title="订单详情" :column="3" :size="size" border>
    <template slot="extra">
      <el-button type="primary" size="small" @click="cancel()" >返回</el-button>
    </template>
    <el-descriptions-item>
      <template slot="label">
        <i class="el-icon-user"></i>
        订单编号:
      </template>
      {{ form.id }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        <i class="el-icon-mobile-phone"></i>
        服务编号
      </template>
      {{ form.number }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        <i class="el-icon-user"></i>
        核销码:
      </template>
      {{ form.verificationCode }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        <i class="el-icon-user"></i>
        商家名称:
      </template>
      {{ form.shopName }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        <i class="el-icon-location-outline"></i>
        买家:
      </template>

      {{ form.userName  }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        <i class="el-icon-tickets"></i>
        订单状态
      </template>
      {{ form.state }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        <i class="el-icon-office-building"></i>
        下单时间:
      </template>
      {{ form.createTime }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        <i class="el-icon-office-building"></i>
        预约时间:
      </template>
      {{ form.subscribeTime }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        <i class="el-icon-office-building"></i>
        金额:
      </template>
      {{ form.abc}}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        <i class="el-icon-office-building"></i>
        服务内容:
      </template>
      {{ form.serviceName }}
    </el-descriptions-item>
  </el-descriptions>

    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder,listOrder1,listOrder2,listOrder3,listOrder4 } from "@/api/order/order";

export default {
  name: "Order",
  data() {
    return {
      aa:'https://lzq-wyc.oss-cn-beijing.aliyuncs.com/file/20240612/组 6(1).png',
      tabPosition: 'left',
      options: [{
          value: '0',
          label: '待支付'
        }, {
          value: '1',
          label: '待使用'
        }, {
          value: '2',
          label: '待评价'
        }, {
          value: '3',
          label: '已取消'
        },  {
          value: '4',
          label: '已退款'
        },
        {
          value: '5',
          label: '已评价'
        }],
        options1: [
           {
          value: '1',
          label: '一星'
        }, {
          value: '2',
          label: '二星'
        }, {
          value: '3',
          label: '三星'
        },  {
          value: '4',
          label: '四星'
        },
        {
          value: '5',
          label: '五星'
        }],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
     // 订单类型时间范围
     daterangeCreateTime: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      orderList2: [],
      orderList3: [],
      orderList4:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createTime:null,
        number: null,
        state: null,
        type: null
      },
      queryParams1: {
        pageNum: 1,
        pageSize: 10,
        commentTime:null,
        orderIdw: null,
        score: null

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getList2();
    this.getList3();
    this.getList4();
  },

  methods: {

    formatUserInfo(row) {
      return row.userInfo;
    },
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listOrder1(this.queryParams1).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getList2() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listOrder2(this.queryParams).then(response => {
        this.orderList2 = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getList3() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listOrder3(this.queryParams).then(response => {
        this.orderList3 = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getList4() {
      this.loading = true;
      this.queryParams1.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams1.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams1.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listOrder4(this.queryParams1).then(response => {
        this.orderList4 = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        number: null,
        shopId: null,
        carId: null,
        userId: null,
        couponId: null,
        remark: null,
        totalPrice: null,
        realPrice: null,
        verificationCode: null,
        qrcode: null,
        subscribeTime: null,
        createTime: null,
        verificationTime: null,
        state: null,
        type: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleQuery2() {
      this.queryParams.pageNum = 1;
      this.getList2();
    },
    aa() {
      this.queryParams.pageNum = 1;
      this.getList3();
    },
    handleQuery4() {
      this.queryParams.pageNum = 1;
      this.getList4();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.handleQuery2();
      this.handleQuery4();
      this.aa();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
        const id = row.id || this.ids;
        this.form = row;
        let str=this.form.abc
        let newStr = str.replace(/<br>/g, '');
        this.form.abc=newStr
        let str1=this.form.userName
        let newStr1 = str1.replace(/<br>/g, '');
        this.form.userName=newStr1
        this.open = true;
        getOrder(id).then(response => {
        this.form.verificationCode = response.data.verificationCode
        })

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单编号为"' + ids + '"的数据项？').then(function() {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('order/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
